package com.platform.controller;

import com.platform.entity.CustomerManagerEntity;
import com.platform.service.CustomerManagerService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 单位客户管理Controller
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2018-03-19 11:52:42
 */
@Controller
@RequestMapping("customerManager")
public class CustomerManagerController {
    @Autowired
    private CustomerManagerService customerManagerService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("customerManager:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<CustomerManagerEntity> customerManagerList = customerManagerService.queryList(query);
        int total = customerManagerService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(customerManagerList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{customerId}")
    @RequiresPermissions("customerManager:info")
    @ResponseBody
    public R info(@PathVariable("customerId") Integer customerId) {
        CustomerManagerEntity customerManager = customerManagerService.queryObject(customerId);

        return R.ok().put("customerManager", customerManager);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("customerManager:save")
    @ResponseBody
    public R save(@RequestBody CustomerManagerEntity customerManager) {
        customerManagerService.save(customerManager);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("customerManager:update")
    @ResponseBody
    public R update(@RequestBody CustomerManagerEntity customerManager) {
        customerManagerService.update(customerManager);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("customerManager:delete")
    @ResponseBody
    public R delete(@RequestBody Integer[]customerIds) {
        customerManagerService.deleteBatch(customerIds);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<CustomerManagerEntity> list = customerManagerService.queryList(params);

        return R.ok().put("list", list);
    }
}
